<%-- 
    Document   : yqwh
    Created on : 2016-7-22, 08:40:50
    Author     : cxhd
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%@include file="../../link.jsp" %>
<!--        <link href="../../css/bootstrap-paper.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="${base}/js/bootstrap.min.js"></script>-->
        <title>仪器管理</title>
    </head>
         <style>
        tr>td{
            padding: 4px 4px 4px 4px;
            /*padding-bottom: 4px;*/
        }
        th{
            padding:4px 4px 4px 4px;
            font:bold;
            text-align:center;
        }
         .error{font-size: 1px; color: red}
    </style>
    <body style="font-family: 微软雅黑;margin-top: 10px;" ng-app="yqwh" ng-controller="mainTab">
          <div class="col-lg-12">
            <div class="panel panel-default" style="overflow: hidden">

                <div class="panel-heading"><span style="float: left">仪器列表</span>
                    <div>
                        <input ng-model="searchContent"  placeholder="名字/仪器型号" style="width:320px; float: left;margin-left: 20px" class="form-control input-sm" />
                        <button ng-click="getDeviceSs()" style="float: left" class="btn btn-success btn-sm"><span class="fa fa-search"></span>&nbsp;&nbsp;搜索</button>

                        <button ng-click="OpenSaveModal()" style="margin-left: 30px;float: left" class="btn btn-info btn-sm"><span class="fa fa-send"></span>&nbsp;&nbsp;添加</button></div>

                    <div style="clear: both"></div>
                </div>

                <table class="table table-striped table-bordered  table-hover ">
                    <thead>
                       <tr>
                               <th class="table-id">序号</th>
                               <th class="table-id">仪器型号</th>
                                <th class="table-title">仪器名</th>
                                <th class="table-type">使用部门</th>
                                 <th class="table-author">样本类型</th>
                                 <th class="table-type">仪器类型</th>
                                  <th class="table-type">代号</th>
                                 <th class="table-set">操作</th>
                            </tr>
                    </thead>
                    <tbody>
                            <tr  ng-repeat="dev in devs" >
                                <td>{{$index}}</td>
                                <td>{{dev.DEVICEMODEL}}</td>
                                <td>{{dev.DEVICENAME}}</td>
                                <td>{{dev.USEDEPARTMENT1}}</td>
                                <td>{{dev.JUDGE}}</td>
                                <td>{{dev.DEVICETYPE1}}</td>
                                <td>{{dev.NOTES}}</td>
                                <td>
                                    <button ng-click="OpenUpdateModal(dev)" class="btn btn-success btn-xs"><span class="fa fa-edit"></span>修改</button>
                                    <button ng-click="deleteDevice(dev)" class="btn btn-danger btn-xs"><span class="fa fa-bolt"></span>删除</button>
                                </td>
                            </tr>
                    </tbody>
                </table>  
                  
                <footer class="panel-heading">
                    <div class="row">
                        <div style="text-align: center" >                
                            <pagination ng-change="pageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="data.currentPage" items-per-page="data.pageSize" total-items="data.bigTotalItems" ng-model="data.bigCurrentPage" max-size="data.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                        </div>
                    </div>
                </footer>

            </div>

        </div>

         <!--<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="editModal">-->
        <div class="modal fade mode-x" role="dialog" aria-labelledby="gridSystemModalLabel" >
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="CloseModel()"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="gridSystemModalLabel">{{title}}仪器</h4>
                    </div>
                    <div class="modal-body">
                        <form  name="formDev" id="profile" >
                            <table style="width: 100%">                             
                                <tr>
                                    <td>仪&nbsp;器  &nbsp;名&nbsp;:<input type="text" name="devicename" ng-model="tmpdevice.DEVICENAME" style="width: 100px" ng-minlength=1 ng-maxlength=20 required/><label style="color:red;">&lowast;</label>
                                         <div class="error" ng-show="formDev.devicename.$dirty && formDev.devicename.$invalid">
                                        <small class="error" ng-show="formDev.devicename.$error.required">仪器名不能为空。</small>
                                        <small class="error" ng-show="formDev.devicename.$error.minlength">仪器名长度不能小于1</small>
                                        <small class="error" ng-show="formDev.devicename.$error.maxlength">仪器名长度不能大于20</small> 
                                        </div>
                                    </td>
                                    <td>使用部门:
                                        <!--<input type="text" ng-model="tmpdevice.USEDEPARTMENT" style="width: 100px"/>-->
                                    <select ng-model="tmpdevice.KSMCPK" name="ks" ng-options="ks.PK as ks.KSMC for ks in kss" style="width: 100px" ng-selected="ks.PK==tmpdevice.KSMCPK">
                                        <option value="" >请选择科室</option>
                                                        </select>
                                        <label style="color:red;">&lowast;</label>
                                         
                                         </div>
                                    </td> 
                                </tr>
                                <tr>
                                    <td>仪器类型：
                                        <!--<input type="text" ng-model="SAMPLEDESCRIBE"/>-->
                                         <select ng-model="tmpdevice.DEVICETYPEPK" name="type" ng-options="devtype.PK as devtype.DEVICETYPEDESC for devtype in devtypes" style="width: 100px" ng-selected="devtype.PK==tmpdevice.DEVICETYPEPK">
                                             <option value="" style="color: red">请选择仪器类型</option>
                                                        </select>
                                        <label style="color:red;">&lowast;</label>
                                    </td>
                              <td>仪器型号:<input type="text" ng-model="tmpdevice.DEVICEMODEL" style="width: 100px"/></td>
                                </tr>          
                                <tr>
                                    <td>出&nbsp;产&nbsp;地&nbsp;：<input type="text" ng-model="tmpdevice.FACTORY" style="width: 100px"/></td> 
                                    <td>数据存储路径：<input type="text" ng-model="tmpdevice.PATH" style="width: 100px"/></td>
                                </tr>
                                <tr ><td>样本类型:
                                        <!--<input type="text" ng-model="tmpdevice.DEVICESTATUS" style="width: 100px"/>-->
                                        <select ng-model="tmpdevice.JUDGE" style="width: 100px">
                                            <option>--请选择--</option>
                                           <option ng-repeat="sa in samp">{{sa.SAMPLEDESCRIBE}}</option>
                                        </select>
                                        <label style="color:red;">&lowast;</label>
                                    </td>
                                    
                                    &nbsp;
                                    <td>串口：<select ng-model="tmpdevice.COMPORTN" style="width: 100px">
                                            <option value="1">COM1</option>
                                            <option value="2">COM2</option>
                                            <option value="3">COM3</option>
                                            <option value="4">COM4</option>
                                            <option value="5">COM5</option>
                                            <option value="6">COM6</option>
                                            <option value="7">COM7</option>
                                            <option value="8">COM8</option>
                                            <option value="9">COM9</option>
                                            <option value="10">COM10</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>波特率：<select ng-model="tmpdevice.BAUDRATES" style="width: 100px">
                                            <option value="1200">1200</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="9600">9600</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </td>
                                    <td>
                                        仪器代号：<input type="text" ng-model="tmpdevice.NOTES" style="width: 100px"/>
                                    </td>
                                </tr>
                            </table>
                        </form>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="CloseModel()">关闭</button>
                        <button  ng-click="saveDevice()" ng-disabled="formDev.$invalid" type="button" class="btn btn-primary"><span class="fa fa-save"></span>&nbsp;&nbsp;保存</button>
                    </div>
                </div>
            </div> 
        </div> 
        
        
    </body>
    <script>
         angular.module("yqwh", ['baseModule', 'ui.bootstrap'])
            .controller("mainTab", function ($scope,base) {
 
                $scope.tmpdevice={PK:""};
                $scope.searchContent="";
                
                   
                $scope.data = {currentPage: 1};
                $scope.setPage = function (pageNo) {
                    $scope.data.currentPage = pageNo;
                };

                $scope.pageChanged = function () {
                    $scope.getDeviceSs();
                };

                $scope.data.maxSize = 10;
                $scope.data.bigTotalItems = 20;
                $scope.data.bigCurrentPage = 1;
                $scope.data.pageSize = 10;

                $scope.getDeviceSs=function(){//显示
                base.post("device/getDeviceS",{pageSize: $scope.data.pageSize, currentPage: $scope.data.currentPage,searchContent:$scope.searchContent}).get(function(data){ //参数 分页参数
//                    console.log(data);
                    if(data){
                       $scope.devs=data.list;
                       $scope.data.bigTotalItems = data.totalRow;
                       for(var i=0;i<$scope.devs.length;i++){
                           if($scope.devs[i].DEVICESTATUS==0){
                               $scope.devs[i].DEVICESTATUS1="未启用";
                           }else if($scope.devs[i].DEVICESTATUS==1){
                               $scope.devs[i].DEVICESTATUS1="已启用";
                           }else if($scope.devs[i].DEVICESTATUS==2){
                               $scope.devs[i].DEVICESTATUS1="维修中";
                           }else{
                               $scope.devs[i].DEVICESTATUS1="输入错";
                           }
                       }
//                       $scope.$apply();
                    }
                })
            }
            $scope.getDeviceSs();
            
            $scope.getKs=function(){//获取科室
                base.post("device/getLisKs",{}).get(function(data){
                    if(data){
                        $scope.kss=data;
                    }
                })
            }
            $scope.getKs();
            $scope.getDevType=function(){//获取仪器类型
                base.post("device/getLisDeviceType").get(function(data){
                    if(data){
                        $scope.devtypes=data;
                    }
                })
            }
            
            $scope.getDevType();
            
             $scope.getSample = function () {
                     base.post("device/getSample").get(function (data) {
                        $scope.samp = data;
                       
                    })
                }
                 $scope.getSample();
               $scope.deleteDevice=function(tmp){
                
                  var gnl=confirm("你真的确定要删除吗?"); //友好提示
                if (gnl==true){ 
                base.post("device/deleteDeviceS",{PK:tmp.PK}).get(function(data){
                    if(data=='true'){
                        alert("删除成功",1000);
                        $scope.getDeviceSs();
                        $scope.$apply();
                    }
                })
            }else{
                return;
            }
            }
                
                 $scope.OpenSaveModal = function () {
                     $scope.title="新增";
                    $scope.tmpdevice.DEVICESTATUS="0";
                    $scope.tmpdevice.COMPORTN="1";
                    $scope.tmpdevice.BAUDRATES="1200";
                    $(".mode-x").modal('show');
                }
                $scope.OpenUpdateModal=function(tmp){
                      $scope.title="修改";
                     $scope.tmpdevice=tmp;
                    $(".mode-x").modal('show');   
                }
               $scope.CloseModel=function(){//关闭窗口的同时清空窗口数据
                   $scope.tmpdevice={PK:""};
                     $scope.tmpdevice.DEVICESTATUS="0";
                    $scope.tmpdevice.COMPORTN="1";
                    $scope.tmpdevice.BAUDRATES="1200";
                   $scope.getDeviceSs();
               }
               
               $scope.saveDevice=function(){//必须要验证 显示序号 和扩展类型为数值
                  
                 if($scope.tmpdevice.KSMCPK==""||$scope.tmpdevice.KSMCPK==null){
                     steveAl("请选择仪器所属科室",1000);
                     return;
                 }
                  if($scope.tmpdevice.DEVICETYPEPK==""||$scope.tmpdevice.DEVICETYPEPK==null){
                     steveAl("请选择仪器类型",1000);
                     return;
                 }
                 base.post("device/getDeviceRep",{PK:$scope.tmpdevice.PK,DEVICEMODEL:$scope.tmpdevice.DEVICEMODEL}).get(function(data){
               
                     if(data=='true'){
                         steveAl("该型号已存在",1000);
                         return;
                     }
                     
                 if($scope.tmpdevice.PK!=""){//修改
                    
                     base.post("device/updateDeviceS",$scope.tmpdevice).get(function(data){
                    if(data=='true'){
                       $scope.getDeviceSs();
                        steveAl("修改成功！",1000);
                    }
                })  
                 }else{//保存 
                    base.post("device/saveDeviceS",$scope.tmpdevice).get(function(data){
                    if(data=='true'){
                       $scope.getDeviceSs();
                        steveAl("新增成功！",1000);
                    }
                })
                 }
                 
                  $(".mode-x").modal('hide');
                 $scope.CloseModel();
                
                
                 })  
               }
            })
    </script>
<!--    <body ng-app="yqwh" ng-controller="sz">
    <style>
        tr>th{ padding: 1px}
    </style>
    <div>
   <div class="col w-lg bg-light dk b-r bg-auto" id="aside" style="background-color: #ffffff;width: 40%">
                <div class="wrapper bg b-b" style="height: 48px;">
                    <button class="btn btn-sm btn-success pull-right" ui-toggle-class="timeline-center" target=".timeline">Center</button>
                    <h4 class="m-n font-thin">仪器浏览</h4>
                </div>
                <div class="wrapper" >
                    <form class="ng-pristine ng-valid">
                        <table  class="table table-striped table-bordered  table-hover" style="width:100%"  >
                            <tr>
                                <th class="table-id">序号</th>
                                <th class="table-title">仪器名</th>
                                <th class="table-type">使用部门</th>
                                 <th class="table-author">使用状态</th>
                                 <th class="table-type">仪器类型</th>
                                  
                            </tr>
                            <tr  ng-repeat="dev in devs" ng-click="getDeviceInfo(dev)">
                                <td>{{$index}}</td>
                                <td>{{dev.DEVICENAME}}</td>
                                <td>{{dev.USEDEPARTMENT1}}</td>
                                <td>{{dev.DEVICESTATUS1}}</td>
                                <td>{{dev.DEVICETYPE1}}</td>
                            </tr>
                        </table>
                    </form>
                    
                    <footer class="panel-heading">
                    <div class="row">
                        <div style="text-align: center" >                
                            <pagination ng-change="pageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="data.currentPage" items-per-page="data.pageSize" total-items="data.bigTotalItems" ng-model="data.bigCurrentPage" max-size="data.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                        </div>
                    </div>
                </footer>
                </div>
            </div>
    <div style="position: fixed;left:40%;top: 0px;bottom: 0px; width:60%;margin-bottom: 20px;">
        <div>
            <button class="btn m-b-xs btn-sm btn-success btn-addon" ng-click="saveDevice()"><i class="fa fa-save"></i>保存</button>
            <button class="btn m-b-xs btn-sm btn-danger btn-addon" ng-click="deleteDevice()"><i class="fa fa-plus"></i>删除</button>
            <button class="btn m-b-xs btn-sm btn-primary btn-addon" ng-click="cancelEvent()"><i class="fa fa-cab"></i>取消</button>
            <button class="btn m-b-xs btn-sm btn-primary btn-addon" ng-click="newDevice()"><i class="fa fa-save"></i>添加仪器</button>
            <button class="btn m-b-xs btn-sm btn-info btn-addon"><i class="fa fa-print"></i>打印</button>
            <button class="btn m-b-xs btn-sm btn-info btn-addon"><i class="fa fa-close"></i>退出</button>
        </div>
            <ul class="nav nav-tabs" role="tablist">
    <li role="presentation" class="active"><a href="/demo/bootstrap3-plugin-tab.htm#home" aria-controls="home" role="tab" data-toggle="tab">基础信息</a></li>
    
  </ul>

  <div class="tab-content">
    <div role="tabpanel" class="tab-pane active" id="home">
       <table class="table table-striped table-bordered  table-hover" style="width:100%" >
            <tr><td>仪器名:<input type="text" ng-model="tmpdevice.DEVICENAME" style="width: 100px"/></td>
                <td>使用部门：
                    <input type="text" ng-model="tmpdevice.USEDEPARTMENT" style="width: 100px"/>
                <select ng-model="tmpdevice.USEDEPARTMENT" ng-options="ks.KSDM as ks.KSMC for ks in kss" style="width: 100px" >
                                    </select>
                </td> 
                <td>仪器类型：
                    <input type="text" ng-model="SAMPLEDESCRIBE"/>
                     <select ng-model="tmpdevice.DEVICETYPE" ng-options="devtype.DEVICETYPE as devtype.DEVICETYPEDESC for devtype in devtypes" style="width: 100px" >
                                    </select>
                </td>
            </tr>          
            <tr><td>仪器型号:<input type="text" ng-model="tmpdevice.DEVICEMODEL" style="width: 100px"/></td>
                <td>出产地：<input type="text" ng-model="tmpdevice.FACTORY" style="width: 100px"/></td> 
                <td>数据存储路径：<input type="text" ng-model="tmpdevice.PATH" style="width: 100px"/></td>
            </tr>
            <tr ><td>仪器状态:
                    <input type="text" ng-model="tmpdevice.DEVICESTATUS" style="width: 100px"/>
                    <select ng-model="tmpdevice.DEVICESTATUS" style="width: 100px">
                        <option value="0">未启用</option>
                        <option value="1">已启用</option>
                        <option value="2">维修中</option>
                    </select>
                </td>
                <td></td> 
                <td></td>
            </tr>
        </table>
  
</div>
     
  </div>
        </div>
    </div>
</body>

    <script>
        angular.module("yqwh",['baseModule', 'ui.bootstrap'])
               .controller("sz", function ($scope,$http) {
                  
                   var so = $scope;
                $scope.data = {currentPage: 1};
                so.setPage = function (pageNo) {
                    $scope.data.currentPage = pageNo;
                };
                so.pageChanged = function () {
                   $scope.getDeviceSs();
                };
                so.data.maxSize = 10;
                so.data.bigTotalItems = 20;
                so.data.bigCurrentPage = 1;
                so.data.pageSize = 10;
                
                   $scope.tmpdevice={PK:""};
              $scope.getDeviceSs=function(){
                $.post("device/getDeviceS",{pageSize: so.data.pageSize, currentPage: so.data.currentPage},function(data){ //参数 分页参数
                    console.log(data);
                    if(data){
                       $scope.devs=data.list;
                       so.data.bigTotalItems = data.totalRow;
                       for(var i=0;i<$scope.devs.length;i++){
                           if($scope.devs[i].DEVICESTATUS==0){
                               $scope.devs[i].DEVICESTATUS1="未启用";
                           }else if($scope.devs[i].DEVICESTATUS==1){
                               $scope.devs[i].DEVICESTATUS1="已启用";
                           }else if($scope.devs[i].DEVICESTATUS==2){
                               $scope.devs[i].DEVICESTATUS1="维修中";
                           }else{
                               $scope.devs[i].DEVICESTATUS1="输入错";
                           }
                       }
                       $scope.$apply();
                       
                    }
                })
            }
            $scope.getDeviceSs();
            $scope.getDeviceInfo=function(info){
                $scope.tmpdevice=info;

            } 
            $scope.getKs=function(){//获取科室
                $.post("device/getLisKs",function(data){
                    if(data){
                        $scope.kss=data;
                    }
                })
            }
            $scope.getKs();
            $scope.getDevType=function(){//获取仪器类型
                $.post("device/getLisDeviceType",function(data){
                    if(data){
                        $scope.devtypes=data;
                    }
                })
            }
            $scope.getDevType();
            $scope.deleteDevice=function(){
                  var gnl=confirm("你真的确定要删除吗?"); //友好提示
                if (gnl==true){ 
                $.post("device/deleteDeviceS",{PK:$scope.tmpdevice.PK},function(data){
                    if(data=='true'){
                        alert("删除成功",1000);
                        $scope.getDeviceSs();
                        $scope.$apply();
                    }
                })
            }else{
                return;
            }
            }
            $scope.cancelEvent=function(){
         $scope.newDevice();
          
            }
            $scope.newDevice=function(){//新项目
                $scope.tmpdevice={PK:""};
            }
            
            $scope.saveDevice=function(){//保存项目或保存修改
                
//                 var test=  JSON.stringify($scope.tesI);
                 
                if( $scope.tmpdevice.PK==""){ //新增 
                alert("新增");
                $.post("device/saveDeviceS",$scope.tmpdevice,function(data){
                    if(data=='true'){
                        $scope.getDeviceSs();

                        alert("新增成功！",1000);
                    }
                })
                  }else{// 修改
                     alert("修改");
                    $.post("device/updateDeviceS",$scope.tmpdevice,function(data){
                    if(data=='true'){
                        $scope.getDeviceSs();
                        alert("修改成功！",1000);
                    }
                })  
                  }
            }
           
        })

    </script>-->
</html>
